// ignore_for_file: file_names, slash_for_doc_comments, must_call_super, unnecessary_overrides, override_on_non_overriding_member, must_be_immutable, prefer_const_constructors, sized_box_for_whitespace, avoid_unnecessary_containers, avoid_print

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:in_app_review/in_app_review.dart';
import 'package:mybase/base/abstract/IFFR.dart';
import 'package:mybase/base/abstract/IFFRefresh.dart';
import 'package:mybase/base/abstract/IFFScaffold.dart';
import 'package:mybase/base/super/FFInk.dart';
import 'package:mybase/base/tool/arouter/FFGoto.dart';
import 'package:mybase/base/tool/color/FFColor.dart';
import 'package:mybase/base/tool/extension/FFNumExt.dart';
import 'package:mybase/base/tool/globalMethod/FFScreenValue.dart';
import 'package:mybase/base/tool/time/FFTime.dart';
import 'package:mybase/base/widget/layout/FFImageButton.dart';
import 'package:mybase/base/widget/layout/FFLineContainer.dart';
import 'package:mybase/base/widget/layout/FFTextButton.dart';
import 'package:mybase/base/widget/page/FFScaffold.dart';
import 'package:mybase/base/tool/extension/FFListExt.dart';
import 'package:mybase/base/tool/sputils/FFSpUtils.dart';
import 'package:myuis/constant/FFSpValue.dart';
import 'package:myuis/constant/PackageValue.dart';
import 'package:myuis/language/LanguageValue.dart';
import 'package:myuis/manager/MyuisManager.dart';

class CommentPage extends FFScaffold {
  String? name;
  bool? userClick;
  String? appStoreId;
  Function(String? eventName)? onFire;

  CommentPage({
    Key? key,
    this.name,
    this.userClick = false,
    required this.appStoreId,
    this.onFire,
  }) : super(key: key);

  @override
  CommentPageState createState() => CommentPageState();

  ///是否评论过
  static bool isCommented(){
    return FFSpUtils.getBoolData(FFSpValue.commented);
  }

  ///上次展示的时间
  static DateTime? lastDisplayedTime() {
    int? second = FFSpUtils.getIntData(FFSpValue.lastCommentPageShow);
    if (second == null) return null;
    return FFTime.secondToDate(second);
  }

}

class CommentPageState extends FFScaffoldState with MFFScaffold {
  /**固定写法 */
  @override
  IFFScaffold get iffScaffold => this;

  @override
  CommentPage get widget => super.widget as CommentPage;

  @override
  IFFRefresh? get iffRefresh => refresh;
  late CommentPageRefresh refresh = CommentPageRefresh(state: this);

  /**固定写法end */

  @override
  void ffInitState() {
    super.ffInitState();
    FFSpUtils.saveIntData(FFSpValue.lastCommentPageShow, FFTime.nowSecond());
  }

  @override
  void ffDispose() {
    if (widget.userClick != true) {
      FFSpUtils.saveIntData(FFSpValue.notLike, FFTime.nowSecond());
    }

    super.ffDispose();
  }

  @override
  Widget? ffBody(BuildContext context) {
    return FFImageButton(
        width: globalScreenWidth(context),
        image: FFImageFactory.asset("assets/images/comment/commentbg.png",
            package: PackageValue.package));
  }

  @override
  Widget? ffBottom(BuildContext context) {
    return FFLineContainer(
      direction: Axis.vertical,
      children: [
        FFTextButton(
          text: LanguageValue.loveApp(getContext()),
          fontSize: 38.sp,
          fontWeight: FontWeight.bold,
          fontColor: Colors.white,
          maxLines: 10,
          alignment: Alignment.center,
          textAlign: TextAlign.center,
        ),
        30.w.heightSpace,
        FFTextButton(
          text: LanguageValue.loveApp2(getContext()),
          fontSize: 18.sp,
          fontColor: rgba(114, 115, 115, 1.0),
          maxLines: 10,
          alignment: Alignment.center,
          textAlign: TextAlign.center,
          fontLineHeight: 1.2,
        ),
        50.w.heightSpace,
        FFInk(
          child: FFTextButton(
            onClick: () async {
              if (widget.onFire != null) {
                widget.onFire!("myuis_click_love");
              }
              await FFGoto.pop(getContext());
              await FFSpUtils.saveBoolData(FFSpValue.commented, true);
              final InAppReview inAppReview = InAppReview.instance;
              inAppReview.openStoreListing(
                  appStoreId: widget.appStoreId, microsoftStoreId: "");
            },
            text: LanguageValue.loveit(getContext()),
            fontSize: 17.sp,
            fontColor: Colors.black,
            maxLines: 10,
            fontWeight: FontWeight.bold,
            padding: EdgeInsets.symmetric(vertical: 20.w),
            margin: EdgeInsets.symmetric(horizontal: 16.w),
            alignment: Alignment.center,
            textAlign: TextAlign.center,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(100.w),
              color: Colors.white,
            ),
          ),
        ),
        16.w.heightSpace,
        FFInk(
          child: FFTextButton(
            onClick: () async {
              //await FFSpUtils.saveIntData(SpValue.notLike, FFTime.nowSecond());
              if (widget.onFire != null) {
                widget.onFire!("myuis_click_nolove");
              }
              FFGoto.pop(getContext());
            },
            text: LanguageValue.noloveit(getContext()),
            fontSize: 17.sp,
            fontColor: rgba(114, 115, 115, 1.0),
            maxLines: 10,
            fontWeight: FontWeight.bold,
            padding: EdgeInsets.symmetric(vertical: 20.w),
            margin: EdgeInsets.symmetric(horizontal: 16.w),
            alignment: Alignment.center,
            textAlign: TextAlign.center,
          ),
        ),
        Container(
          height: globalScreenPaddingBottom(context),
        ),
      ],
    );
  }
}

class CommentPageRefresh with MFFRefresh {
  CommentPageState state;

  CommentPageRefresh({required this.state});

  @override
  bool? ffCanRefreshHead() {
    return true;
  }

  @override
  ScrollPhysics? get ffRefreshPhysics => NeverScrollableScrollPhysics();

  @override
  ffRefresh(bool isHead) {
    ffRefreshResult(isHead, test, state);
  }

  //具体请求业务
  Future<IFFR> test(IRefreshParam? iRefreshParam) async {
    return R(rStatus: RStatus.result);
  }
}
